package com.pdstudio.carrecom.ui.fragment.more;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.http.RequestParams;
import com.pdstudio.carrecom.R;
import com.pdstudio.carrecom.api.HttpExecuteJson;
import com.pdstudio.carrecom.api.ServiceHelper;
import com.pdstudio.carrecom.api.HttpExecuteJson.httpReturnJson;
import com.pdstudio.carrecom.app.AppContext;
import com.pdstudio.carrecom.app.UIHelper;
import com.pdstudio.carrecom.bean.PhoneValideCode;
import com.pdstudio.carrecom.ui.activity.more.ActivityValidePhoneAg;

public class FragmentValidePhoneAg2 extends Fragment {

	private View _view;
	private Activity _context;

	private Button mNextStep;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		_view = inflater.inflate(R.layout.fragment_more_validephoneag2,
				container, false);
		_context = getActivity();
		initialView();
		return _view;
	}

	public void initialView() {

		mNextStep = (Button) _view.findViewById(R.id.more_vp_ag_next);
		mNextStep.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				getActivity().finish();
			}
		});
	}

//	private void DoJson(String json) {
//		PhoneValideCode edv = null;
//		try {
//			edv = new Gson().fromJson(json, new TypeToken<PhoneValideCode>() {
//			}.getType());
//			if ((edv != null)
//					&& (edv.msg.equals(ServiceHelper.msg_code_sucess))) {
//				// 原本在initview的代码放在这下面
//				try {
//					mValideCode.setText(edv.code);
//
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			} else {
//				UIHelper.ToastMessage(_context, "获取验证码失败");
//
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//
//	}

//	private httpReturnJson mLoginListener = new httpReturnJson() {
//		@Override
//		public void onFailure(int error, String msg) {
//			UIHelper.ToastMessage(_context, "获取验证码失败" + msg);
//		}
//
//		@Override
//		public void onCancel() {
//			// TODO Auto-generated method stub
//			UIHelper.ToastMessage(_context, "获取验证码失败");
//		}
//
//		// 获取到饲料配方类型成功
//		public void onSuccess(String result) {
//			// TODO Auto-generated method stub
//			// UIHelper.ToastMessage(_context,"总条数=" + result + "");
//			DoJson(result);
//		}
//	};

	private void DoJsonAgPost(String json) {
		PhoneValideCode edv = null;
		try {
			edv = new Gson().fromJson(json, new TypeToken<PhoneValideCode>() {
			}.getType());
			if ((edv != null)
					&& (edv.msg.equals(ServiceHelper.msg_code_sucess))) {
				// 原本在initview的代码放在这下面
				try {
					UIHelper.ToastMessage(_context, "手机重验证成功！");
					getActivity().finish();
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else {
				UIHelper.ToastMessage(_context, "手机重验证失败!"+edv.msg);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private httpReturnJson mAgPostListener = new httpReturnJson() {
		@Override
		public void onFailure(int error, String msg) {
			UIHelper.ToastMessage(_context, "手机重验证失败" + msg);
		}

		@Override
		public void onCancel() {
			// TODO Auto-generated method stub
			UIHelper.ToastMessage(_context, "手机重验证失败");
		}

		// 获取到饲料配方类型成功
		public void onSuccess(String result) {
			// TODO Auto-generated method stub
			// UIHelper.ToastMessage(_context,"总条数=" + result + "");
			DoJsonAgPost(result);
		}
	};

}
